package com.allqj.sfx.ddd.member.infrastructure.repository;

import com.allqj.sfx.ddd.member.domain.entity.admin.AdminUser;
import com.allqj.sfx.ddd.member.domain.repository.AdminUserRepository;
import com.allqj.sfx.ddd.member.infrastructure.converter.AdminUserDataConverter;
import com.allqj.sfx.ddd.member.infrastructure.dao.AdminUserDAO;
import com.allqj.sfx.ddd.member.infrastructure.po.MemberAdminUserDO;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * @author sjw
 * @className AdminUserRepositoryImpl
 * @date 2022/7/20 15:22
 * @description: AdminUserRepository实现
 * Repository接口定义位于domain层
 * Repository接口具体实现位于infrastructure层
 * 与底层db解耦
 */
@Repository
public class AdminUserRepositoryImpl implements AdminUserRepository {
    // 数据访问层
    private final AdminUserDAO dao;

    public AdminUserRepositoryImpl(AdminUserDAO dao) {
        this.dao = dao;
    }

    @Override
    public AdminUser queryByPhone(String phone) {
        Optional<MemberAdminUserDO> adminUserDO = dao.findByPhoneAndIsdeleteFalse(phone);
        return adminUserDO.map(memberAdminUserDO -> AdminUserDataConverter.INSTANCE.do2Entity(memberAdminUserDO)).orElse(null);
    }
}
